// pages/login/login.js


Page({

  /**
   * 页面的初始数据
   */
  data: {
    usermessage:[],
    usercode:[],
    userworkoder:[],
    usermvctHour:"",
    userTxHour:"",
    userstatus:"",
    usercontractStatus:"",
    userwaringstatus:"",
    tomo: {
      value1: 0,
      value2: 0,
      value3: 0,
    },
    cybe: {
      value1: 0,
      value2: 0,
      value3: 0,
    },
    radi: {
      value1: 0,
      value2: 0,
      value3: 0,
    },
    equipCount:0,
    repairCount:0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let token = this.Store.getItem('token');
    this.getRightData()
    console.log(token, '打印')
    if (!token) {
      this.Router.push({
        path: "login",
        query: {test:111},
        openType: 'reLaunch',
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    console.log(this.data, '我记得是这样取的')

  },
  swiperChange(e){
    console.log(e)
    let index =e.detail.current
    this.getAllData(this.data.usercode[index])
  },
  userhome(){
    this.Router.push("userhome")
  },
  test(){
    wx.login({
      success (res) {
        if (res.code) {
          //发起网络请求
          wx.request({
            url: 'https://api.weixin.qq.com/sns/jscode2session?appid=wxfc755f2a080708ab&secret=2888e91fca0bcab6ba60d9bc217c8359&js_code='+res.code+'&grant_type=authorization_code',
            method:'GET',
            data: {
            },
            success(result){
            console.log(result)
            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
    // wx.getUserProfile({
    //   desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
    //   success: (res) => {
    //     console.log(res)
    //   }
    // })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
      //设备号初始化
      equipmentInit() {
        let self = this;
        this.axios.custom("AllInstalledProducts", "serialOrLotNumbers", {
            id: self.Store.getItem("userid"),
          })
          .then(function (response) {
            console.log(response);
            self.getAllData(response.data[0])
            self.setData({
              usercode:response.data
            })
          });
      },
  //消息通知
  getRightData() {
    console.log("jinlai")
    let self =this
    this.axios.custom("MainPage", "getMainPageMessage", {customerId:this.Store.getItem("customerId"),typeName:this.Store.getItem("identity")})
      .then(function (response) {
        console.log(response)
        if (response.data.messages != undefined) {
          self.setData({
            usermessage:response.data.messages
          })
        }
      });
      this.axios.custom("MainPage", "getMainPageInfo", {})
      .then(function (res) {
        console.log(res);
        if (
          res.data != undefined &&
          res.data.equipmentWorkOrder.length > 0
        ) {
          res.data.equipmentWorkOrder.forEach((e) => {
            if (e.type == "TOMO") {
              self.data.tomo.value1 = e.notBegin;
              self.data.tomo.value2 = e.running;
              self.data.tomo.value3 = e.completed;
              self.setData({
                tomo:self.data.tomo
              })
            }
            if (e.type == "Radixact") {
              self.data.radi.value1 = e.notBegin;
              self.data.radi.value2 = e.running;
              self.data.radi.value3 = e.completed;
              self.setData({
                radi:self.data.radi
              })
            }
            if (e.type == "CK") {
              self.data.cybe.value1 = e.notBegin;
              self.data.cybe.value2 = e.running;
              self.data.cybe.value3 = e.completed;
              self.setData({
                cybe:self.data.cybe
              })
            }
          });
        }
        self.setData({
          equipCount:res.data.equipmentCountViewModel.equipCount,
          repairCount:res.data.equipmentCountViewModel.repairCount
        })

      });
  },
      //获取主页数据
      getAllData(code) {
        console.log(code)
        let self = this;
           this.axios.custom("MainPage", "getMainPageEquipment", {id:code})
          .then(function (response) {
           console.log(response)
              self.setData({
                userworkoder:response.data.allOpenWorkOrders,
                userstatus:response.data.allInstalledProducts.status,
                usercontractStatus:response.data.allInstalledProducts.contractStatus
              })
          });
        this.axios.custom("MainPage", "getMainPageEquipmentLog", {id:code})
          .then( (response)=> {
            console.log(response)
            self.setData({
              usermvctHour:response.data.beamOnHourSum.imageOn,
              userTxHour:response.data.beamOnHourSum.treatmentOn,
              userwaringstatus:response.data.warningStatus
            })
          });
      },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})